class Admin::WelcomeController < ApplicationController
  before_action :authenticate_super_admin!

  def index
  end

  def setting
    @roles = YAML::load(SETTING.roles)
    @contest_categories = YAML::load(SETTING.contest_categories)
  end

  def update_setting
    if params[:role_name]
      SETTING.roles = YAML::dump(YAML::load(SETTING.roles) + [params[:role_name].to_sym])
      SETTING.save
    end
    if params[:category_name]
      SETTING.contest_categories = YAML::dump(YAML::load(SETTING.contest_categories) + [params[:category_name].to_sym])
      SETTING.save
    end
    redirect_to admin_setting_path
  end

  def setting_remove_role
    role = params[:role_name].to_sym
    roles = YAML::load(SETTING.roles)
    roles.delete(role)
    SETTING.roles = YAML::dump(roles)
    SETTING.save
    redirect_to admin_setting_path
  end

  def setting_remove_category
    category = params[:category_name].to_sym
    categories = YAML::load(SETTING.contest_categories)
    categories.delete(category)
    SETTING.contest_categories = YAML::dump(categories)
    SETTING.save
    redirect_to admin_setting_path
  end
end
